#include "Composite.h"
#include "Component.h"
#include <algorithm>
#include <iostream>

using namespace std;

Composite::Composite(string name):Component(name){
}

Composite::~Composite(){
}

void Composite::Add(Component* c){
	children.push_back(c);
}

void Composite::Remove(Component* c){
	vector<Component*>::iterator result = find( children.begin( ),children.end( ), c );
	if (result != children.end( ))
		children.erase(result);
}

void Composite::Display(int depth){
	for (int i = 0; i < depth; i++)
	{
		cout<< "-";
	}
	cout<< _name <<endl;

	for (unsigned int index = 0; index < children.size();index++)
	{
		children[index]->Display(depth + 2);
	}
}